package com.lch.designpattern.singleton.lazy;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @author: liuchenhui
 * @create: 2019-04-16 23:10
 **/
public class LazyInnerClassSingletonTest {
    public static void main(String[] args) {
//        Thread thread1 = new Thread(new LazyInnerClassSingletonRunable());
//        Thread thread2 = new Thread(new LazyInnerClassSingletonRunable());
//
//        thread1.start();
//        thread2.start();
//
//        System.out.println("End");
        // 很无聊的进行破坏
        try {
            Class<?> clazz = LazyInnerClassSingleton.class;

            // 通过反射拿到私有的构造方法
            Constructor c = clazz.getDeclaredConstructor();
            c.setAccessible(true);

            Object o1 = c.newInstance();

            Object o2 = c.newInstance();

            System.out.println(o1 == o2);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}